package com.howtodoinjava.security;

import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Component;

/**
 * @author cuong.nd Enable custom encoder
 * 
 */

@Component
public class CustomPasswordEncoder implements PasswordEncoder {

	private static int BCRYPT_WORKING_FACTOR = 10;

	public String encodePassword(String rawPass, Object salt) {
		return BCrypt.hashpw(rawPass, BCrypt.gensalt(BCRYPT_WORKING_FACTOR));
	}

	public boolean isPasswordValid(String enPass, String rawPass, Object salt) {
		return BCrypt.checkpw(rawPass, enPass);
	}

}
